package com.sf.osms.dep.processor.handler.convert;

import java.util.Date;
import java.util.Map;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.sf.osms.dep.domain.Agent;
import com.sf.osms.dep.domain.Router;
import com.sf.osms.dep.processor.exception.ExceptionConstants;
import com.sf.osms.dep.processor.exception.RouterException;
import com.sf.osms.dep.processor.model.EventModel;
import com.sf.osms.dep.processor.util.FileUtil;
import com.sf.osms.dep.processor.util.RouterConstants;

/**
 * 进行路由基本信息的填充（这部分信息不需要代理文件中提供）
 * @author sfhq1405
 *
 */
public class BasicInfoConverter implements Converter{
	
	private static Logger logger = LoggerFactory.getLogger(BasicInfoConverter.class);
	
	
	@Override
	public void convert(Router router, Map<String, String> routerFieldAndStr,Agent agentInfo,EventModel eventModel,
			ConverterChain chain) throws RouterException{
				//默认router值
				router.setAgentId(agentInfo.getId());
				router.setAgentCode(agentInfo.getName()); //默认agentCode为代理的Name
				router.setInsertTime(new Date());
				router.setFileName(FileUtil.getTreeFileName(eventModel.getFile().getName())); //设置文件名称
				router.setStatusDt(new Date());
				router.setCountry(agentInfo.getCountry());
				//网点号和操作员工号为必须信息
				if(StringUtils.isBlank(agentInfo.getNetNum()) || StringUtils.isBlank(agentInfo.getOperatorId())){
					logger.error("******代理：" + agentInfo.getName() +",处理文件：" + eventModel.getFile().getAbsolutePath()+
							"," + "代理没有对应的网点信息******");
					router.addFailReasonList(ExceptionConstants.AGENT_NET_INFO_NOT_FIND_CODE);
	
				}
				router.setSendCount(0);
				router.setNetNum(agentInfo.getNetNum());
				router.setOperatorId(agentInfo.getOperatorId());
				router.setBarSn(RouterConstants.AGENT_BAR_SN_FILE);
				chain.convert(router, routerFieldAndStr, agentInfo, eventModel, chain);
	}

}
